<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="discussion-macros.html"/>
  <xi:include href="admin.html"/>
  <head>
    <title>Discussion Forums</title>
  </head>

  <?python
    from tracdiscussion.api import format_to_oneliner_no_links
    from multiproject.core.configuration import conf
  ?>

  <py:with vars="is_edit = discussion.forum.id and not req.args.submit">
    <body>
      <h2>Forums</h2>

      <form id="${is_edit and 'edit-forum-form' or 'add-forum-form'}" class="addnew" method="post" action="${panel_href()}">
        <div class="shaded-box">
        <fieldset id="rightpanel">
          <legend>${is_edit and 'Edit Forum:' or 'Add Forum:'}</legend>

          <div class="inputrow">
            <div class="headtextfield">Name:</div>
            <div class="inputfield">
              <py:if test="conf.news_forum_name == discussion.forum.name">
                <input type="text" id="name" name="name" readonly="readonly" value="${is_edit and discussion.forum.name or ''}"/>
              </py:if>
              <py:if test="conf.news_forum_name != discussion.forum.name or conf.news_forum_name == ''">
                <input type="text" id="name" name="name" value="${is_edit and discussion.forum.name or ''}"/>
              </py:if>
            </div>
          </div>
          <div class="inputrow">
            <div class="headtextfield">Subject:</div>
            <div class="inputfield">
              <input type="text" id="subject" name="subject" value="${is_edit and discussion.forum.subject or ''}"/>
            </div>
          </div>
          <div class="inputrow">
            <div class="headtextfield">Description:</div>
            <div class="inputfield">
              <input type="text" id="description" name="description" value="${is_edit and discussion.forum.description or ''}"/>
            </div>
          </div>
          <div class="inputrow">
            <div class="headtextfield">Moderators:</div>
            <div class="inputfield">
            <py:choose>
              <select py:when="len(discussion.users) > 0 and 7 >
                len(discussion.users)" id="moderators" name="moderators"
                multiple="on">
                <py:for each="user in discussion.users">
                  <py:choose>
                    <option py:when="is_edit and user in
                      discussion.forum.moderators" value="$user"
                      selected="selected">$user</option>
                    <option py:otherwise="" value="$user">$user</option>
                  </py:choose>
                </py:for>
              </select>
              <select py:when="len(discussion.users) > 6" id="moderators"
                name="moderators" size="6" multiple="on">
                <py:for each="user in discussion.users">
                  <py:choose>
                    <option py:when="is_edit and user in
                      discussion.forum.moderators" value="$user"
                      selected="selected">$user</option>
                    <option py:otherwise="" value="$user">$user</option>
                  </py:choose>
                </py:for>
              </select>
              <input py:otherwise="" type="text" id="moderators" name="moderators" value="${discussion.forum.moderators}"/>
            </py:choose><br/>
            </div>
          </div>
          <div class="inputrow">
            <div class="headtextfield">Registered subscribers:</div>
            <div class="inputfield">
            <py:choose>
              <select py:when="len(discussion.users) > 0 and 7 >
                len(discussion.users)" id="subscribers" name="subscribers"
                multiple="on">
                <py:for each="user in discussion.users">
                  <py:choose>
                    <option py:when="is_edit and user in
                      discussion.forum.subscribers" value="$user"
                      selected="selected">$user</option>
                    <option py:otherwise="" value="$user">$user</option>
                  </py:choose>
                </py:for>
              </select>
              <select py:when="len(discussion.users) > 6" id="subscribers"
                name="subscribers" size="6" multiple="on">
                <py:for each="user in discussion.users">
                  <py:choose>
                    <option py:when="is_edit and user in
                      discussion.forum.subscribers" value="$user"
                      selected="selected">$user</option>
                    <option py:otherwise="" value="$user">$user</option>
                  </py:choose>
                </py:for>
              </select>
            </py:choose><br/>
            </div>
          </div>
          <div class="inputrow">
            <div class="headtextfield">Unregistered subscribers:</div>
            <div class="inputfield">
              <input type="text" id="unregistered_subscribers"
                name="unregistered_subscribers" value="${is_edit and
                ' '.join(discussion.forum.unregistered_subscribers)}"/><br/>
            </div>
          </div>
          
          <py:choose>
            <div py:when="len(discussion.groups) > 1" class="inputrow">
              <div class="headtextfield">Forum Group:</div>
              <div class="inputfield">
              <select id="group" name="group">
                <py:for each="group in discussion.groups">
                  <py:choose>
                    <option py:when="is_edit and (group.id ==
                      discussion.forum.forum_group)" value="${group.id}"
                      selected="selected">${group.name}</option>
                    <option py:otherwise="" value="${group.id}">
                      ${format_to_oneliner_no_links(discussion.env, context,
                      group.name)}</option>
                  </py:choose>
                </py:for>
              </select>
              </div>
            </div>
            <input py:otherwise="" type="hidden" name="group" value=""/>
          </py:choose>

          <div class="buttons">
            <input type="submit" name="submit" value="${is_edit and 'Edit' or 'Add'}" class="secondaryButton" />

            <py:if="is_edit">
              <input type="button" name="cancel" value="Cancel" onclick="location.href = '${panel_href()}'" class="secondaryButton" />
            </py:if> 

            <input py:if="is_edit" type="hidden" name="forum" value="${discussion.forum.id}"/>
            <input type="hidden" name="discussion_action" value="${is_edit and 'post-edit' or 'post-add'}"/>
          </div>
        </fieldset>
        </div>
      </form>

      <py:choose>
        <form py:when="len(discussion.forums)" method="post"
          action="${panel_href()}">
          <table id="forum-list" class="listing">
            <thead>
              <tr>
                <th class="sel">&nbsp;</th>
                ${sortable_th(discussion.order, discussion.desc, 'id', 'ID',
                  panel_href())}
                ${sortable_th(discussion.order, discussion.desc, 'name', 'Name',
                  panel_href())}
                ${sortable_th(discussion.order, discussion.desc, 'subject',
                  'Subject', panel_href())}
                ${sortable_th(discussion.order, discussion.desc, 'description',
                  'Description', panel_href())}
                ${sortable_th(discussion.order, discussion.desc, 'moderators',
                  'Moderators', panel_href())}
                ${sortable_th(discussion.order, discussion.desc, 'subscribers',
                  'Subscribers', panel_href())}
                <py:if test="len(discussion.groups) > 1">
                  ${sortable_th(discussion.order, discussion.desc,
                    'forum_group', 'Group', panel_href())}
                </py:if>
              </tr>
            </thead>
            <tbody>
              <py:for each="line, forum in enumerate(discussion.forums)">
                <tr class="${line % 2 and 'even' or 'odd'}">
                  <td class="sel">
                    <input type="checkbox" name="selection" value="${forum.id}"/>
                  </td>
                  <td class="id">
                    <div class="id">
                      <a href="${panel_href(forum.id)}">
                        <span>${forum.id}</span>
                      </a>
                    </div>
                  </td>
                  <td class="name">
                    <div class="name">
                      <a href="${panel_href(forum.id)}">
                        <span>${format_to_oneliner_no_links(discussion.env,
                          context, forum.name) or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td class="subject">
                    <div class="subject">
                      <a href="${panel_href(forum.id)}">
                        <span>${format_to_oneliner_no_links(discussion.env,
                          context, forum.subject) or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td class="description">
                    <div class="description">
                      <a href="${panel_href(forum.id)}">
                        <span>${format_to_oneliner_no_links(discussion.env,
                          context, forum.description) or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td class="moderators">
                    <div class="moderators">
                      <a href="${panel_href(forum.id)}">
                        <span>${' '.join(forum.moderators) or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td class="subscribers">
                    <div class="subscribers">
                      <a href="${panel_href(forum.id)}">
                        <span>${' '.join(forum.subscribers) or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td py:if="len(discussion.groups) > 1" class="group">
                    <div py:for="group in discussion.groups" py:if="group.id ==
                      forum.forum_group" class="group">
                      <a href="${panel_href(forum.id)}">
                        <span>${format_to_oneliner_no_links(discussion.env,
                          context, group.name)}</span>
                      </a>
                    </div>
                  </td>
                </tr>
              </py:for>
            </tbody>
          </table>
          <br/>
          <div class="buttons">
            <input type="submit" name="remove" value="Remove selected items" onclick="return confirm('Do you really want to remove selected items?')" />
            <input type="hidden" name="discussion_action" value="delete"/>
          </div>
        </form>
        <div py:otherwise="">
          <p class="help">As long as you don't add any items to the list, this
            field will remain completely hidden from the user interface.</p>
          <br style="clear: right"/>
        </div>
      </py:choose>
    </body>
  </py:with>
</html>
